﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BlackBBS.Helpers;
using BlackBBS.Models.Data;
using BlackBBS.Enums;

namespace BlackBBS.Menus
{
    public class BBSList : MenuBase
    {
        public BBSList()
        {
        }

        public override void SendMenu()
        {
            this.Connection.SetCurrentArea(Area.CallHistory);
            var handled = false;
            while (!handled)
            {
                this.Connection.ClearScreen();
                this.Connection.SendFile("BBSLIST.ANS");
                handled = this.HandleResponse(this.Connection.SendScript("BBSLIST.MNU"));
            }
        }


        public bool HandleResponse(Dictionary<string, string> response)
        {
            if (response == null || response.Count == 0)
            {
                return false;
            }
            var key = (response.First().Key ?? string.Empty).ToLower();
            var value = (response.First().Value ?? string.Empty).ToLower();

            switch (value)
            {
                case "a": // add to bbs list
                    this.AddNew();
                    return false;

                case "b": // blackbbs sites
                    break;

                case "e": // edit bbs list
                    break;

                case "s": // see bbs list
                    break;

                case "q": // quit to main 
                    base.SendToMain();
                    return true;
            }
            return false;
        }

        void AddNew()
        {
            var forecolor = ANSIForeGroundColors.Blue;
            var backcolor = ANSIBackgroundColors.Black;
            var inputColorFormat = ANSIColorHelper.AnsiColor(ANSIForeGroundColors.White, ANSIBackgroundColors.Blue);
            var confirm = this.Connection.GetResponse(ANSIColorHelper.AnsiColorMessage("Add BBS To List?", forecolor, backcolor), inputColorFormat, "No");
            if (string.IsNullOrEmpty(confirm) || !confirm.StartsWith("y", StringComparison.CurrentCulture))
            {
                return;
            }
            this.Connection.SendFile("BBBSLADD.ANS");

            var phoneNumberUSFormat = this.Connection.GetResponse(ANSIColorHelper.AnsiColorMessage("Is Phone Number US Format (###-###-####)?", forecolor, backcolor), inputColorFormat, "Yes");
            var phoneNumber = this.Connection.GetResponse(ANSIColorHelper.AnsiColorMessage("Enter phone number (###-###-####)", ANSIForeGroundColors.White, ANSIBackgroundColors.Blue), inputColorFormat);
            var bbsName = this.Connection.GetResponse(ANSIColorHelper.AnsiColorMessage("Enter the name of the BBS", ANSIForeGroundColors.White, ANSIBackgroundColors.Blue), inputColorFormat);
            var bbsDesc = this.Connection.GetResponse(ANSIColorHelper.AnsiColorMessage("Enter short description for the BBS", ANSIForeGroundColors.White, ANSIBackgroundColors.Blue), inputColorFormat);
            var bbsSysop = this.Connection.GetResponse(ANSIColorHelper.AnsiColorMessage("Enter name of SysOp", ANSIForeGroundColors.White, ANSIBackgroundColors.Blue), inputColorFormat);
            var bbsSoftware = this.Connection.GetResponse(ANSIColorHelper.AnsiColorMessage("Enter BBS software description", ANSIForeGroundColors.White, ANSIBackgroundColors.Blue), inputColorFormat);

            // TODO; send data back with a confirm

        }
    }
}
